package com.bk.game.screen;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.Music;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.bk.game.global.BkGlobal;

/**
 * 描述:广告主页
 * 
 * @author linqiang(866116)
 * @Since 2012-9-5
 */
public class AdScreen implements Screen {

	// 绘图用的SpriteBatch
	private SpriteBatch batch;
	// 纹理
	private TextureRegion bg;
	private TextureAtlas ta;

	private boolean hasinit, first;

	@Override
	public void dispose() {
		ta.dispose();
		batch.dispose();
	}

	@Override
	public void hide() {
		ta.dispose();
	}

	@Override
	public void pause() {
	}

	@Override
	public void render(float arg0) {
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		Gdx.gl.glClearColor(0f, 0f, 0f, 0f);
		batch.begin();
		batch.draw(bg, 0, 0, Gdx.graphics.getWidth(), Gdx.graphics.getHeight());
		batch.end();
		if (!hasinit && BkGlobal.manager.update()) {
			hasinit = true;
			if (BkGlobal.currentGame != null)
				BkGlobal.currentGame.setScreen(new MainScreen());
		}

	}

	@Override
	public void resize(int arg0, int arg1) {
	}

	@Override
	public void resume() {
	}

	@Override
	public void show() {
		Gdx.input.setCatchBackKey(true);
		if (!first) {
			BkGlobal.factorx = Gdx.graphics.getWidth() / 640f;
			BkGlobal.factory = Gdx.graphics.getHeight() / 920f;

			batch = new SpriteBatch(); // 实例化
			ta = new TextureAtlas(Gdx.files.internal("ad.pack"));
			bg = ta.findRegion("Default");
			// 初始化一下AssetManager实例
			BkGlobal.manager = new AssetManager();
			// 把资源加入载入列表
			// 主页资源
			BkGlobal.manager.load("main.pack", TextureAtlas.class);
			// 游戏资源
			BkGlobal.manager.load("cat0.pack", TextureAtlas.class);
			BkGlobal.manager.load("cat1.pack", TextureAtlas.class);
			BkGlobal.manager.load("cat2.pack", TextureAtlas.class);
			BkGlobal.manager.load("cat3.pack", TextureAtlas.class);
			BkGlobal.manager.load("bg.pack", TextureAtlas.class);
			BkGlobal.manager.load("btn.pack", TextureAtlas.class);
			BkGlobal.manager.load("boom.pack", TextureAtlas.class);
			// 帮助
			BkGlobal.manager.load("help.pack", TextureAtlas.class);
			BkGlobal.manager.load("end.pack", TextureAtlas.class);
			BkGlobal.manager.load("rank.pack", TextureAtlas.class);

			// 音乐文件
			BkGlobal.manager.load("neko1.mp3", Sound.class);
			BkGlobal.manager.load("neko2.mp3", Sound.class);
			BkGlobal.manager.load("neko3.mp3", Sound.class);
			BkGlobal.manager.load("neko4.mp3", Sound.class);
			BkGlobal.manager.load("neko5.mp3", Sound.class);
			BkGlobal.manager.load("end2.mp3", Sound.class);

			BkGlobal.manager.load("dog.mp3", Sound.class);
			BkGlobal.manager.load("bgm.mp3", Music.class);
			BkGlobal.manager.load("btn.mp3", Sound.class);
			BkGlobal.manager.load("buzzer.mp3", Sound.class);
			BkGlobal.manager.load("fue.mp3", Sound.class);
			BkGlobal.manager.load("kekka.mp3", Sound.class);
			first = true;
		}
	}

}
